<#--
  //form select 下拉框标签
-->
<#macro select  name <#--如果name不传则于id一直-->
                id = "" <#-- ID 如果ID 不传则跟name一致-->
                value = ""
                required= false <#-- 是否必输-->
                class = "form-control" <#-- 输入框样式-->
                butClass = "" <#-- 是否带提示样式-->
                helpTip = ""  <#--帮助提示 -->
                dictType = "" <#-- 字典类型，从字典里获取 -->
                serviceCode = "" <#-- 指定送那个服务获取字典、默认本系统 -->
                items = "" <#-- 列表数据，可接受对象集合  -->
                itemLabel = ""	<#--  指定列表数据中的什么属性名作为option的标签名 -->
                itemValue =  ""	<#-- 指定列表数据中的什么属性名作为option的value值 -->
                status = true <#-- 检测状态-->
                multiple= false <#--  是否为多选框 -->
                blankValue =  "false" <#-- 是否默认有个空白选择项目 -->
                blankLabel =  "" <#-- 空白选择默认值 -->
                placeholder=""
                readonly = false <#-- 是否只读-->
                viewMode =false
                viewClass="label label-default"
                template = false <#-- 控件是否做template用-->
                >
    <#local  Assname="${id}"/>
    <#if name != "">
        <#local Assname="${name}"/>
    </#if>
    <#local AssId=""/>
    <#if id == "">
        <#local AssId="${Assname}"/>
    <#else>
        <#local AssId="${id}"/>
    </#if>

    <#if viewMode>    <#-- view 用法 <@f.select name="roleIdList" multiple = true value="${selectRoles}"  items=roles itemLabel="roleName" itemValue="id" required=true view=true />    -->
        <#if dictType !="">    <#-- dictType !=""  -->
            <#list dict.getType('${dictType}','${serviceCode}') as d>
                <#list value?split(",") as k>
                    <#if k == (d['${dictValue}']?c)>
                        <span class="${viewClass}">${i18n("${d['${dictLabel}']}")}</span>
                    </#if>
                </#list>
            </#list>
        <#else>  <#-- else <#-- dictType !=""   -->
            <#list items as d>
                <#list value?split(",") as k>
                    <#if k?string == d['${itemValue}']?string>
                        <span class="${viewClass}">${i18n("${d['${itemLabel}']}")}</span>
                    </#if>
                </#list>
            </#list>
        </#if>   <#-- end dictType !=""  -->
    <#else>  <#-- view else -->

        <#if !multiple>
            <#if template>
            <input  class="select2_hidden" id="${AssId}_hidden" select_id="${AssId}" type="hidden" value="${value}"/>
            </#if>
            <select id="<#if !template>${AssId?replace(".","_")}<#else>${AssId}</#if>" name="<#if name != "">${name}<#else>${AssId}</#if>" class="${class}" <#if required> required</#if><#if readonly> disabled="disabled"</#if> <#if placeholder != "">placeholder="${i18n("${placeholder}")}"</#if>>
                <#if blankValue !="false"><option value="${blankValue}">${i18n("${blankLabel}")}</option></#if>
                <#if dictType !="">
                    <#list dict.getType('${dictType}','${serviceCode}')>
                        <#items as d>
                            <#if status  && d.status?default('') !=''>
                                <#if d.status =='0' >
                                    <#if value == "" && blankValue == "false">
                                        <option value="${d.dictValue}" <#if d.isDefault =='Y' >selected="selected"</#if>>${i18n("${d.dictLabel}")}</option>
                                    <#else>
                                        <#assign a=0 />
                                        <#list value?split(",") as x>
                                            <#if x == d.dictValue>
                                                <#assign a=1 />
                                            </#if>
                                        </#list>
                                        <option value="${d.dictValue}" <#if a == 1 >selected="selected"</#if>>${i18n("${d.dictLabel}")}</option>
                                    </#if>
                                </#if>
                            <#else>
                                <#if value == "" && blankValue == "false">
                                    <option value="${d.dictValue}" <#if d.isDefault =='Y' >selected="selected"</#if>>${i18n("${d.dictLabel}")}</option>
                                <#else>
                                    <#assign a=0 />
                                    <#list value?split(",") as x>
                                        <#if x == d.dictValue>
                                            <#assign a=1 />
                                        </#if>
                                    </#list>
                                    <option value="${d.dictValue}" <#if a == 1 >selected="selected"</#if>>${i18n("${d.dictLabel}")}</option>
                                </#if>
                            </#if>
                        </#items>
                    </#list>
                <#else>
                    <#list items>
                        <#items as d>
                            <#if status && d.status?default('') !=''>
                                <#if d.status =='0' >
                                    <#if value == "">
                                        <option value="${d['${itemValue}']}">${i18n("${d['${itemLabel}']}")}</option>
                                    <#else>
                                        <#assign a=0 />
                                        <#list value?split(",") as x>
                                            <#if x == "${d['${itemValue}']}">
                                                <#assign a=1 />
                                            </#if>
                                        </#list>
                                        <option value="${d['${itemValue}']}" <#if a == 1 >selected="selected"</#if>>${i18n("${d['${itemLabel}']}")}</option>
                                    </#if>
                                </#if>
                            <#else>
                                <#if value == "">
                                    <option value="${d['${itemValue}']?default('')}">${i18n("${d['${itemLabel}']?default('')}")}</option>
                                <#else>
                                    <#assign a=0 />
                                    <#list value?split(",") as x>
                                        <#if x == "${d['${itemValue}']}">
                                            <#assign a=1 />
                                        </#if>
                                    </#list>
                                    <option value="${d['${itemValue}']}" <#if a == 1 >selected="selected"</#if>>${i18n("${d['${itemLabel}']}")}</option>
                                </#if>
                            </#if>
                        </#items>
                    </#list>
                </#if>
            </select>
        <#--        <@compress single_line=true>-->
            <script type="text/javascript">
                $(function() {
                    $("#<#if !template>${AssId?replace(".","_")}<#else>${AssId}</#if>").on("change",function(e){
                        var data = $("#<#if !template>${AssId?replace(".","_")}<#else>${AssId}</#if>").select2("data");
                        <#if template>
                        $("#${AssId}_hidden").val(data[0].id);
                        </#if>
                        /* 选择框回调事件*/
                        if(typeof selectCallback == 'function'){
                            selectCallback('<#if !template>${Assname?replace(".","_")}<#else>${Assname}</#if>', 'change', data);
                        }
                    });
                })
            </script>
        <#--        </@compress>-->
        </#if>

        <#if multiple>
            <input id="<#if !template>${AssId?replace(".","_")}<#else>${AssId}</#if>" type="hidden" name="<#if id == "">${name}<#else>${AssId}</#if>"/>
            <select id="__<#if !template>${AssId?replace(".","_")}<#else>${AssId}</#if>slt" class="${class}" multiple="true" <#if class= "selectpicker">data-none-selected-text="${i18n("请选择")}"</#if> <#if required> required</#if> <#if readonly> disabled="disabled"</#if>>
                <#if blankValue !="false"><option value="${blankValue}">${i18n("${blankLabel}")}</option></#if>
                <#if dictType !="">
                    <#list dict.getType('${dictType}','${serviceCode}')>
                        <#items as d>
                            <#if status>
                                <#if d.status =='0' >
                                    <#if value == "" && blankValue == "false">
                                        <option value="${d.dictValue}" <#if d.isDefault =='Y' >selected="selected"</#if>>${i18n("${d.dictLabel}")}</option>
                                    <#else>
                                        <#assign a=0 />
                                        <#list value?split(",") as x>
                                            <#if x == d.dictValue>
                                                <#assign a=1 />
                                            </#if>
                                        </#list>
                                        <option value="${d.dictValue}" <#if a == 1 >selected="selected"</#if>>${i18n("${d.dictLabel}")}</option>
                                    </#if>
                                </#if>
                            <#else>
                                <#if value == "" && blankValue == "false">
                                    <option value="${d.dictValue}" <#if d.isDefault =='Y' >selected="selected"</#if>>${i18n("${d.dictLabel}")}</option>
                                <#else>
                                    <#assign a=0 />
                                    <#list value?split(",") as x>
                                        <#if x == d.dictValue>
                                            <#assign a=1 />
                                        </#if>
                                    </#list>
                                    <option value="${d.dictValue}" <#if a == 1 >selected="selected"</#if>>${i18n("${d.dictLabel}")}</option>
                                </#if>
                            </#if>
                        </#items>
                    </#list>
                <#else>
                    <#list items>
                        <#items as d>
                            <#if status>
                                <#if d.status =='0' >
                                    <#if value == "">
                                        <option value="${d['${itemValue}']}">${i18n("${d['${itemLabel}']}")}</option>
                                    <#else>
                                        <#assign a=0 />
                                        <#list value?split(",") as x>
                                            <#if x == "${d['${itemValue}']}">
                                                <#assign a=1 />
                                            </#if>
                                        </#list>
                                        <option value="${d['${itemValue}']}" <#if a == 1 >selected="selected"</#if>>${i18n("${d['${itemLabel}']}")}</option>
                                    </#if>
                                </#if>
                            <#else>
                                <#if value == "">
                                    <option value="${d['${itemValue}']}">${i18n("${d['${itemLabel}']}")}</option>
                                <#else>
                                    <#assign a=0 />
                                    <#list value?split(",") as x>
                                        <#if x == "${d['${itemValue}']}">
                                            <#assign a=1 />
                                        </#if>
                                    </#list>
                                    <option value="${d['${itemValue}']}" <#if a == 1 >selected="selected"</#if>>${i18n("${d['${itemLabel}']}")}</option>
                                </#if>
                            </#if>
                        </#items>
                    </#list>
                </#if>
            </select>
        <#--        <@compress single_line=true>-->
            <script type="text/javascript">
                $(function() {
                    <#if value !="">
                    $("#<#if !template>${AssId?replace(".","_")}<#else>${AssId}</#if>").val(opt.form.selectSelects("__<#if !template>${AssId?replace(".","_")}<#else>${AssId}</#if>slt"));
                    </#if>
                    $("#__<#if !template>${AssId?replace(".","_")}<#else>${AssId}</#if>slt").on("change",function(e){
                        $("#<#if !template>${AssId?replace(".","_")}<#else>${AssId}</#if>").val(opt.form.selectSelects("__<#if !template>${AssId?replace(".","_")}<#else>${AssId}</#if>slt"));
                        /* 选择框回调事件*/
                        if(typeof selectCallback == 'function'){
                            var data = opt.form.selectSelects("__<#if !template>${AssId?replace(".","_")}<#else>${AssId}</#if>slt");
                            selectCallback('<#if !template>${Assname?replace(".","_")}<#else>${Assname}</#if>', 'change', data);
                        }
                    })
                })
            </script>
        <#--        </@compress>-->
        </#if>
    </#if>  <#-- view end if -->
    <#if helpTip!=""><span class="help-block m-b-none"><i class="fa fa-info-circle" style="color: red"></i>${helpTip}</span></#if>
</#macro>